﻿using Application.MainModule.VirtualAccountsManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Domain.MainModule.VirtualAccounts;
using Domain.MainModule.Entities;
using System.Collections.Generic;

using Infraestructure.CrossCutting.IoC;

namespace Application.MainModule.Tests
{
    /// <summary>
    ///This is a test class for VirtualAccountManagementServiceTest and is intended
    ///to contain all VirtualAccountManagementServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class VirtualAccountManagementServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for AddVirtualAccount
        ///</summary>
        [TestMethod()]
        public void AddVirtualAccount_Invoke_Test()
        {
            //Arrange
            IVirtualAccountManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IVirtualAccountManagementService>();
            Guid virtualAccountId = Guid.Parse("ABCDF456-1234-AADD-AAFF-AAAACCBBBBBB");
            Guid userId = Guid.NewGuid();
            VirtualAccount virtualAccount = new VirtualAccount()
                    {
                        VirtualAccountId = virtualAccountId,
                        IsEnabled = true,
                        Balance = 50,
                        UserId = userId
                    };
            VirtualAccount result = null;

            //Act
            target.AddVirtualAccount(virtualAccount);

            //Assert
            result = target.FindVirtualAccountById(virtualAccountId);
            Assert.IsNotNull(result);
            Assert.AreEqual(virtualAccountId, result.VirtualAccountId);
            target.RemoveVirtualAccount(result);
        }

        /// <summary>
        ///A test for ChangeVirtualAccount
        ///</summary>
        [TestMethod()]
        public void ChangeVirtualAccount_Invoke_Test()
        {
            //Arrange
            IVirtualAccountManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IVirtualAccountManagementService>();
            Guid virtualAccountId = Guid.Parse("ABCDF456-1234-AABB-AAFF-AAAACCBBBBBB");
            VirtualAccount virtualAccount;
            VirtualAccount result = null;

            //Act
            virtualAccount = target.FindVirtualAccountById(virtualAccountId);
            virtualAccount.Balance = 100;
            target.ChangeVirtualAccount(virtualAccount);

            //Assert
            result = target.FindVirtualAccountById(virtualAccountId);
            Assert.IsNotNull(result);
            Assert.AreEqual(virtualAccountId, result.VirtualAccountId);
            Assert.AreEqual(100, result.Balance);
        }

        /// <summary>
        ///A test for FindVirtualAccountById
        ///</summary>
        [TestMethod()]
        public void FindVirtualAccountById_Invoke_Test()
        {
            //Arrange
            IVirtualAccountManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IVirtualAccountManagementService>();
            Guid virtualAccountId = Guid.Parse("ABCDF456-1234-AABB-AAFF-AAAACCBBBBBB");
            VirtualAccount virtualAccount;

            //Act
            virtualAccount = target.FindVirtualAccountById(virtualAccountId);

            //Assert
            Assert.IsNotNull(virtualAccount);
            Assert.AreEqual(virtualAccountId, virtualAccount.VirtualAccountId);
        }

        /// <summary>
        ///A test for FindVirtualAccounts
        ///</summary>
        [TestMethod()]
        public void FindVirtualAccounts_Invoke_Test()
        {
            ////Arrange
            //IVirtualAccountManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IVirtualAccountManagementService>();
            //Guid virtualAccountId = Guid.Parse("ABCDF456-1234-AABB-AAFF-AAAACCBBBBBB");
            //Guid userId = 
            //List<VirtualAccount> virtualAccounts = null;

            ////Act
            //virtualAccounts = target.FindVirtualAccounts(userId);

            ////Assert
            //Assert.IsNotNull(virtualAccounts);
            //Assert.AreEqual(virtualAccountId, virtualAccounts[0].VirtualAccountId);
        }

        /// <summary>
        ///A test for RemoveVirtualAccount null virtual account throw argument null exception.
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void RemoveVirtualAccount_NullVirtualAccountThrowArgumentNullException_Test()
        {
            //Arrange
            IVirtualAccountManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IVirtualAccountManagementService>();
            
            //Act
            target.RemoveVirtualAccount(null);
        }

        /// <summary>
        ///A test for RemoveVirtualAccount
        ///</summary>
        [TestMethod()]
        public void RemoveVirtualAccount_Invoke_Test()
        {
            //Arrange
            IVirtualAccountManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IVirtualAccountManagementService>();
            Guid virtualAccountId = Guid.Parse("ABCDF456-1234-AADD-AAFF-AAAACCBBBBBB");
            VirtualAccount virtualAccount = new VirtualAccount()
            {
                VirtualAccountId = virtualAccountId,
                IsEnabled = true,
                Balance = 50
            };
            VirtualAccount result = null;

            //Act
            target.AddVirtualAccount(virtualAccount);
            target.RemoveVirtualAccount(virtualAccount);

            //Assert
            result = target.FindVirtualAccountById(virtualAccountId);
            Assert.IsNull(result);
        }
    }
}
